export BUILD=build
export HOME=$(PWD)
export PREFIX=$(HOME)/$(BUILD)
export PKG_CONFIG_PATH=$(PREFIX)/lib/pkgconfig
export PKG_CONFIG_PATH:=$(PREFIX)/lib64/pkgconfig:$(PKG_CONFIG_PATH)
LIBNL=libnl-3.4.0
IW=iw
OPENSSL=openssl-3.4.1
HOSTAPD=hostap/hostapd
IPTABLES=iptables-1.4.20
UDHCP=udhcp-0.9.8

all: do-it-all

do-it-all:libnl iw openssl hostapd iptables udhcp

libnl:
	mkdir -p $(PREFIX)
	tar -xvzf libnl-3.4.0.tar.gz
	cd $(LIBNL) && \
 	./configure --build=x86_64-linux-gnu --host=$(HOST) --prefix=$(PREFIX) CC=$(CC)  && \
 	make  && make install

iw:
	cd $(IW) && \
	make CC=$(CC) && mv $(IW) $(PREFIX)/bin
 
openssl:
	cd $(OPENSSL) && \
 	./config no-asm no-shared no-async --prefix=$(PREFIX)  --cross-compile-prefix=$(CROSS_COMPILE) && \
 	sed -i 's/-m64//g' Makefile && \
 	make CC=$(CC) && make install

hostapd:
	cd $(HOSTAPD) && \
 	cp defconfig .config && \
 	make CC=$(CC) && \
 	make install DESTDIR=$(PREFIX)
 
iptables:
	tar jxvf iptables-1.4.20.tar.bz2
	cd $(IPTABLES) && \
 	./configure --prefix=$(PREFIX) --host=$(HOST) && \
 	make && make install
	mv $(BUILD)/usr/local/bin/*  $(BUILD)/bin

udhcp:
	cd $(UDHCP) && \
 	make

clean:libnl-clean iw-clean openssl-clean hostapd-clean iptables-clean udhcp-clean

libnl-clean:
	cd $(LIBNL) && make clean

iw-clean:
	cd $(IW) && make clean

openssl-clean:
	cd $(OPENSSL) && make clean

hostapd-clean:
	cd $(HOSTAPD) && make clean

iptables-clean:
	cd $(IPTABLES) && make clean

udhcp-clean:
	cd $(UDHCP) && make clean
